<?php

function nz_Null($variable) {
    if ($variable == "")
        return "Null";
    else
        return "'" . $variable . "'";
}

class Lineamientos extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    var $ie;
    var $p1;
    var $p2;
    var $p3;
    var $Obs1;
    var $p4;
    var $p5;
    var $p6;
    var $usuario_id;
    var $usuario_actualiza_id;
    var $fecha_actualiza;

    function get_last_ten_lineamientos($ie) {
        $query = $this->db->query("SELECT * FROM lineamientos WHERE ie=$ie");
        if ($query->num_rows() == 0)
            return 0;
        else
            return $query->result();
    }

    function Guardar($ie) {

        if (is_numeric($_POST['Id'])) {
            $band = false;
            //$this->Id = $_POST['Id'];
        }else
            $band = true;

        $this->p1 = $_POST['p1'];
        $this->p2 = $_POST['p2'];
        $this->p3 = $_POST['p3'];
        $this->p4 = $_POST['p4'];
        $this->p5 = $_POST['p5'];
        $this->p6 = $_POST['p6'];
        $this->ie = $_POST['ie'];
        if ($band == false) {
            $this->db->query("UPDATE lineamientos SET ie = " . nz_Null($_POST['ie']) . " , p1 = '" . $_POST['p1'] . "' , p2 = '" . $_POST['p2'] . "' , p3 = '" . $_POST['p3'] . "' , p4 = '" . $_POST['p4'] . "' , p5 = '" . $_POST['p5'] . "' , p6 = '" . $_POST['p6'] . "' , usuario_actualiza_id = '" . $this->session->userdata("usuarioId") . "' , fecha_actualiza = now() WHERE Id = '" . $_POST['Id'] . "'");
        } else {
            $this->usuario_id = $this->session->userdata("usuarioId");
            $this->db->insert('lineamientos', $this);
        }
        return true;
    }

}

?>
